import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import '../../spaces/image_space/record_list.dart';
import '../../spaces/report_space/report_list.dart';
import '../../pages/station/station_equip_list.dart';
import '../../pages/station/stationcheck_list.dart';

import '../../model/station.dart';
import '../../spaces/filespace/fileSpace.dart';

import 'station_info.dart';
import 'station_record_home.dart';

class StationPage extends StatefulWidget {
  @override
  StationPage(this.station);
  final Station station;

  @override
  createState() => new StationPageState();
}

class StationPageState extends State<StationPage>
    with SingleTickerProviderStateMixin {
  var tabController;
//  定义底部导航列表
  final List<BottomNavigationBarItem> bottomTabs = [
    new BottomNavigationBarItem(icon: new Icon(Icons.info), label: ('信息')),
    new BottomNavigationBarItem(icon: new Icon(Icons.image), label: ('设备')),
    new BottomNavigationBarItem(icon: new Icon(Icons.report), label: ('巡检')),
    new BottomNavigationBarItem(icon: new Icon(Icons.list), label: ('记录')),
  ];

  Widget getBody(int i) {
    if (i == 0) return StationInfoPage(widget.station);
    //if (i == 1) return RecordListPage(widget.station.Guid, true);
    if (i == 1) return StationEquipListPage(widget.station);
    if (i == 2)
      return StationCheckListPage(widget.station.Guid, widget.station);
    if (i == 3) return StationRecordHome(widget.station);
    if (i == 3) return ReportListPage(widget.station.Guid);
    if (i == 4)
      return FileSpacePage(widget.station.Guid, widget.station.STNM, true);
    return new Container();
  }

  int currentIndex = 0; //当前索引
  late Widget currentPage; //当前页面

  @override
  void initState() {
    super.initState();
    this.tabController = new TabController(
        vsync: this, // 动画效果的异步处理
        length: 3 // tab 个数
        );

    currentPage = getBody(0);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: new AppBar(
          // title: bottomTabs[currentIndex].title,
          //title: Text(widget.station.STNM),
          title: Container(
        child: currentIndex == 3
            ? TabBar(
                controller: this.tabController,
                tabs: [
                  Tab(text: "文字"),
                  Tab(text: "照片"),
                  Tab(text: "文件"),
                  //Tab(text: "文件"),
                ],
              )
            : Text(widget.station.STNM),
        width: 240.0,
      )),
      bottomNavigationBar: new BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          currentIndex: currentIndex,
          items: bottomTabs,
          fixedColor: Colors.blue,
          onTap: (index) {
            setState(() {
              currentIndex = index;
              currentPage = getBody(currentIndex);
            });
          }),
      body: currentIndex == 3
          ? TabBarView(
              controller: this.tabController,
              children: [
                ReportListPage(widget.station.Guid),
                RecordListPage(widget.station.Guid, true),
                FileSpacePage(widget.station.Guid, widget.station.STNM, true)
              ],
            )
          : currentPage,
    );
  }
}
